<?php
	require_once("../conexion/conexion.php");
	require_once("../Funciones/funciones_publicas.php");
	require_once("../Mantenedores/Empleado.php");
	require_once("../Mantenedores/AFP.php");
	$fun = new funciones_publicas();
	$emp = new Empleado();
	$afp = new AFP();
	$agno = date('Y');


	//sueldo base
	if(isset($_GET['sueldoBase']))
	{ $sueldoBase = $_GET['sueldoBase'];}
	//cadena con datos imponibles
	if(isset($_GET['cad']))
	{ $var = $_GET['cad'];}
	//sucursal
	if(isset($_GET['suc']))
	{ $suc = $_GET['suc'];}
	//rut empleado
	if(isset($_GET['rut']))
	{ $rut = $_GET['rut'];}
	$nombre = $emp->BuscaEmpleado($rut);
	//sueldo
	if(isset($_GET['sueldo']))
	{ $sueldo = $_GET['sueldo'];}
	//gratificacion
	if(isset($_GET['gratif']))
	{ $gratif = $_GET['gratif'];}
	//cadena con datos no imponibles
	if(isset($_GET['cadenaNo']))
	{ $cadenaNo = $_GET['cadenaNo'];}
	//AFP nombre
	if(isset($_GET['cod']))
	{ $cod = $_GET['cod'];}
	$nombreAFP = $afp->BuscaNombreAFP($cod);
	//AFP descuento
	if(isset($_GET['valorAFP']))
	{ $valorAFP = $_GET['valorAFP'];}
	//descuento AFP
	if(isset($_GET['dctoAFP']))
	{ $dctoAFP = $_GET['dctoAFP'];}
	//isapre
	if(isset($_GET['isapre']))
	{ $isapre = $_GET['isapre'];}
	//isapre valor
	if(isset($_GET['isapreValor']))
	{ $isapreValor = $_GET['isapreValor'];}
	//diferencia de isapre
	if(isset($_GET['difSalud']))
	{ $difSalud = $_GET['difSalud'];}
	//diferencia de seguro cesantia
	if(isset($_GET['seguro']))
	{ $seguro = $_GET['seguro'];}	
	//cadena con descuentos
	if(isset($_GET['dcto']))
	{ $dcto = $_GET['dcto'];}
	//dias trabajados
	if(isset($_GET['dias']))
	{ $dias = $_GET['dias'];}
	//valor uf
	if(isset($_GET['uf']))
	{ $uf = $_GET['uf'];}
	//valor que se pacto
	if(isset($_GET['pactada']))
	{ $pactada = $_GET['pactada'];}
	//fecha de emision
	if(isset($_GET['emision']))
	{ $emision = $_GET['emision'];}
	//mes liquidacion
	if(isset($_GET['mes']))
	{ $mes = $_GET['mes'];}
	$mesActual = $fun->SeleccionaMes($mes);
	//cadena prestamo
	if(isset($_GET['cadPres']))
	{ $cadPres = $_GET['cadPres'];}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Vista Previa - Liquidaci&oacute;n</title>
<style>
.encabezado
{
	font-family:Verdana, Arial, Helvetica, sans-serif;
	font-size:16px;
	font-weight:bold;
}
.texto
{
	font-family:Verdana, Arial, Helvetica, sans-serif; 
	font-size:12px; 
	font-weight:bold;
}
</style>
<script>
function window.onbeforeprint()
{ 
	boton=document.getElementById("btn_Imprimir");
	boton.style.display = 'none'; 
} 
function window.onafterprint()
{ 
	boton=document.getElementById("btn_Imprimir"); 
	boton.style.display = 'block'; 
}

function Imprimir()
{
	window.print()
}
</script>
</head>

<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td colspan="2"><label class="encabezado">LIQUIDACI&Oacute;N DE REMUNERACIONES</label></td>
	<td><div style="margin-left:140px;"><img src="../imagen/td_logo2.png" height="55" width="155" /></div></td>
</tr>
<tr>
  <td colspan="3">&nbsp;</td>
</tr>
<tr>
  <td><label class="texto">SUCURSAL: </label><label style="font-size:13px;"><?php echo $suc;?></label></td>
  <td>&nbsp;</td>
  <td><label class="texto">MES:</label>&nbsp;&nbsp;<label style="font-size:16px;"><?php echo $mesActual;?> - <?php echo $agno;?></label></td>
</tr>
<tr>
  <td colspan="3"><hr /></td>
</tr>
<tr>
	<td colspan="3"><label class="texto">EMPRESA:</label>&nbsp;<label style="font-size:13px;">ASESORIAS,CAPACIT. Y SERVIC. FISHING PARTNERS LTDA.</label></td>
</tr>
<tr>
  <td colspan="2"><label class="texto">RUT:</label>&nbsp;<label style="font-size:13px;">77987930-5</label></td>
  <td><label class="texto">C.C:</label>&nbsp;<label style="font-size:13px;">4</label></td>
</tr>
<tr>
  <td colspan="3"><hr /></td>
</tr>
<tr>
  <td colspan="3"><label class="texto">TRABAJADOR Sr(a):</label>&nbsp;<label style="font-size:13px;"><?php echo $nombre;?></label></td>
</tr>
<tr>
  <td colspan="2"><label class="texto">R.U.T:</label>&nbsp;<label style="font-size:13px;"><?php echo $rut;?></label></td>
  <td><label class="texto">Secc.:</label>&nbsp;<label style="font-size:13px;"><?php echo $suc;?></label></td>
</tr>
<tr>
  <td colspan="3"><hr /></td>
</tr>
<tr>
  <td><label class="texto">COTIZACI&Oacute;N PACTADA:</label>&nbsp;<label style="font-size:13px;"><?php echo $pactada;?></label></td>
  <td>&nbsp;</td>
  <td><label class="texto">VALOR UF:</label>&nbsp;<label style="font-size:13px;"><?php echo $uf;?></label></td>
</tr>
<tr>
  <td><label class="texto">DIAS TRABAJADOS:</label>&nbsp;<label style="font-size:13px;"><?php echo $dias;?></label></td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td colspan="3"><hr /></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td colspan="3"><div align="center"><label class="texto">HABERES</label></div></td>
</tr>
<tr><td colspan="3"><hr /></td></tr>
<tr>
	<td>&nbsp;</td>
  	<td><div align="center"><label class="texto">HABERES IMPONIBLES</label></div></td>
  	<td>&nbsp;</td>
</tr>
<tr>
  <td width="27%"><label style="font-size:13px;">SUELDO BASE</label></td>
  <td width="52%">&nbsp;</td>
  <td width="21%"><div align="right" style="margin-right:70px;"><?php echo $sueldoBase;?></div></td>
</tr>
<tr>
  <td width="27%"><label style="font-size:13px;">GRATIFICACION</label></td>
  <td width="52%">&nbsp;</td>
  <td width="21%"><div align="right" style="margin-right:70px;"><?php echo number_format($gratif,0,',','.');?></div></td>
</tr>
<?php
if($dias!=30)
{
	$sueldoB = str_replace ( ".", "",$sueldoBase);
	$nuevoSueldo = $sueldoB-$sueldo;
?>
	<tr>
	  <td width="27%"><label style="font-size:13px;">DIAS FALLAS (<?php echo (30-$dias); ?>)</label></td>
	  <td width="52%">&nbsp;</td>
	  <td width="21%"><div align="right" style="margin-right:66px;">(-<?php echo number_format($nuevoSueldo,0,',','.')?>)</div></td>
	</tr>
<?php }?>
<?php
	$vectorImp = explode(";",$var);
	$cant = (count($vectorImp)-1)/2;
	$vectorImpNo = explode(";",$cadenaNo);
	$cantNo = (count($vectorImpNo)-1)/2;
	//echo $cant;
	$i = 0;
	$cont = 0;
	$suma = 0;
	$sumaNo = 0;
	while($i<$cant)
	{
		echo "<tr>";
		echo "<td width=\"27%\"><label style=\"font-size:13px;\">".strtoupper($vectorImp[$cont])."</label></td>";
		echo "<td width=\"52%\">&nbsp;</td>";
		echo "<td width=\"21%\"><div align='right' style='margin-right:70px;'>".number_format($vectorImp[$cont+1],0,',','.')."</div></td>";
		echo "</tr>";
		$i++;
		$suma = $suma+$vectorImp[$cont+1];
		$cont = $cont+2;
	}?>
<tr>
	<td>&nbsp;</td>
  	<td>&nbsp;</td>
  	<td><label>----------------</label></td>
</tr>
<tr>
	<td>&nbsp;</td>
  	<td><div align="center"><label class="texto">TOTAL HABERES IMPONIBLES ==></label></div></td>
  	<td><div align="right" style="margin-right:70px;"><?php echo number_format(($suma+$sueldo+$gratif),0,',','.');?></div></td>
</tr>
<tr>
	<td colspan="3"><hr /></td>
</tr>
<tr>
	<td>&nbsp;</td>
  	<td><div align="center"><label class="texto">HABERES NO IMPONIBLES</label></div></td>
  	<td>&nbsp;</td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
	<?php
	$i = 0;
	$cont = 0;
	while($i<$cantNo)
	{
		echo "<tr>";
		echo "<td width=\"27%\"><label style=\"font-size:13px;\">".strtoupper($vectorImpNo[$cont])."</label></td>";
		echo "<td width=\"52%\">&nbsp;</td>";
		echo "<td width=\"21%\"><div align='right' style='margin-right:70px;'>".number_format($vectorImpNo[$cont+1],0,',','.')."</div></td>";
		echo "</tr>";
		$i++;
		$sumaNo = $sumaNo+$vectorImpNo[$cont+1];
		$cont = $cont+2;
	}
	?>
</tr>
<tr>
	<td>&nbsp;</td>
  	<td>&nbsp;</td>
  	<td><label>----------------</label></td>
</tr>
<tr>
	<td>&nbsp;</td>
  	<td><div align="center"><label class="texto">TOTAL HABERES NO IMPONIBLES ==></label></div></td>
  	<td><div align="right" style="margin-right:70px;"><?php echo number_format($sumaNo,0,',','.');?></div></td>
</tr>
<tr>
	<td>&nbsp;</td>
  	<td><div align="center"><label class="texto">TOTAL DE HABERES ==></label></div></td>
  	<td><div align="right" style="margin-right:70px;"><?php $haberesTotal = ($sumaNo+$suma+$sueldo+$gratif);echo number_format($haberesTotal,0,',','.');?></div></td>
</tr>
<tr><td colspan="3"><hr /></td></tr>
<tr>
	<td colspan="3"><div align="center"><label class="texto">DESCUENTOS</label></div></td>
</tr>
<tr><td colspan="3"><hr /></td></tr>
<tr>
	<td><label style="font-size:13px;">AFP&nbsp;&nbsp;<?php echo $nombreAFP;?></label></td>
	<td><div align="center"><?php echo $dctoAFP;?></div></td>
	<td><div align="right" style="margin-right:70px;"><?php echo number_format($valorAFP,0,',','.');?></div></td>
</tr>
<tr>
  <td colspan="2"><label style="font-size:13px;"><?php echo $isapre;?></label></td>
  <td><div align="right" style="margin-right:70px;"><?php echo number_format($isapreValor,0,',','.')?></div></td>
</tr>
<tr>
  <td><?php if($difSalud!=""){?><label style="font-size:13px;">DIFERENCIA DE ISAPRE</label><?php }?>
  </td>
  <td>&nbsp;</td>
  <td><?php if($difSalud!=""){?><div align="right" style="margin-right:70px;"><?php echo number_format($difSalud,0,',','.')?></div><?php }?>
  </td>
</tr>
<tr>
  <td><label style="font-size:13px;">SEGURO CESANTIA</label></td>
  <td>&nbsp;</td>
  <td><div align="right" style="margin-right:70px;"><?php echo number_format($seguro,0,',','.');?></div></td>
</tr>
<?php
	$vectorPres = explode(";",$cadPres);
	$cantPres = (count($vectorPres)-1)/2;
	
	$i = 0;
	$cont = 0;
	$sumaPres = 0;
	while($i<$cantPres)
	{
		echo "<tr>";
		echo "<td width=\"27%\"><label style=\"font-size:13px;\">PRESTAMO</label></td>";
		echo "<td width=\"52%\"><div align='center'>".$vectorPres[$cont]."</div></td>";
		echo "<td width=\"21%\"><div align='right' style='margin-right:70px;'>".number_format($vectorPres[$cont+1],0,',','.')."</div></td>";
		echo "</tr>";
		$i++;
		$sumaPres = $sumaPres+$vectorPres[$cont+1];
		$cont = $cont+2;
	}?>
<?php
	$vectorDcto = explode(";",$dcto);
	$cantDcto = (count($vectorDcto)-1)/2;
	
	$i = 0;
	$cont = 0;
	$sumaDcto = 0;
	while($i<$cantDcto)
	{
		echo "<tr>";
		echo "<td width=\"27%\"><label style=\"font-size:13px;\">".strtoupper($vectorDcto[$cont])."</label></td>";
		echo "<td width=\"52%\">&nbsp;</td>";
		echo "<td width=\"21%\"><div align='right' style='margin-right:70px;'>".number_format($vectorDcto[$cont+1],0,',','.')."</div></td>";
		echo "</tr>";
		$i++;
		$sumaDcto = $sumaDcto+$vectorDcto[$cont+1];
		$cont = $cont+2;
	}?>
<tr>
	<td>&nbsp;</td>
  	<td>&nbsp;</td>
  	<td><label>----------------</label></td>
</tr>
<tr>
	<td>&nbsp;</td>
  	<td><div align="center"><label class="texto">TOTAL DESCUENTOS ==></label></div></td>
  	<td><div align="right" style="margin-right:70px;"><?php $dctoTotal = ($sumaDcto+$valorAFP+$isapreValor+$difSalud+$seguro+$sumaPres);echo number_format($dctoTotal,0,',','.');?></div></td>
</tr>
<tr><td colspan="3"><hr /></td></tr>
<tr>
	<td>&nbsp;</td>
  	<td><div align="center"><label class="texto">ALCANCE LIQUIDO ==></label></div></td>
  	<td><div align="right" style="margin-right:70px;"><?php $liquido = ($haberesTotal-$dctoTotal);echo number_format($liquido,0,',','.');?></div></td>
</tr>
<tr>
	<td>&nbsp;</td>
  	<td><div align="center"><label class="texto">TOTAL A PAGAR ==></label></div></td>
  	<td><div align="right" style="margin-right:70px;"><?php $liquido = ($haberesTotal-$dctoTotal);echo number_format($liquido,0,',','.');$pal = $fun->numletras($liquido);?></div></td>
</tr>
<tr><td colspan="3">Son:&nbsp;<?php echo $pal;?></td></tr>
<tr><td colspan="3"><hr /></td></tr>
<?php
$resumen = 'Certifico que he recibido de ASESORIAS,CAPACIT. Y SERVIC. FISHING PARTNERS LTDA., a mi entera satisfacci&oacute;n
el Saldo indicado en la presente liquidaci&oacute;n y no tengo cargo ni cobro posteriores que hacer.'; 
?>
<tr><td colspan="3"><label style="font-size:14px;"><?php echo $resumen;?></label></td></tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr><td colspan="2"><label class="texto">FECHA EMISION:&nbsp;<?php echo $emision;?></label></td>
<td><label>__________________</label></td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td><label>Recib&iacute; Conforme</label></td>
</tr>
<tr><td colspan="3"><div align="center"><input name="btn_Imprimir" id="btn_Imprimir" type="button" value="Imprimir" onclick="Imprimir();" /></div></td></tr>
</table>
</body>
</html>

